#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <stdlib.h>
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    int **numbers;
    numbers = (int **)malloc(sizeof(int *) * N);
    for (int i = 0; i < N; i++) numbers[i] = (int *)malloc(sizeof(int) * N);

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> numbers[i][j];
            cin.ignore(); // 消耗换行符
        }
    }

    for (int i = 0; i < M; i++) {
        string temp;
         // 忽略之前的换行符
        getline(cin, temp, ' ');

        vector<int> operations;
        int operation = -1;

        if (temp == "insertVertex") {
            operation = 0;
        }
        if (temp == "insertEdge") {
            operation = 1;
            int i, j, k;
            cin >> i >> j >> k;
            operations.push_back(i);
            operations.push_back(j);
            operations.push_back(k);
        }
        if (temp == "removeVertex") {
            operation = 2;
            int i;
            cin >> i;
            operations.push_back(i);
        }
        if (temp == "removeEdge") {
            operation = 3;
            int i, j;
            cin >> i >> j;
            operations.push_back(i);
            operations.push_back(j);
        }

        if (operation == 0) {
            int **temp;
            N++;
            temp = (int **)malloc(sizeof(int *) * N);
            for (int i = 0; i < N; i++) temp[i] = (int *)malloc(sizeof(int) * N);
            for (int i = 0; i < N; i++) {
                if (i != N - 1)
                    for (int j = 0; j < N; j++) {
                        if (j != N - 1) temp[i][j] = numbers[i][j];
                        else temp[i][j] = 0;
                    }
                else {
                    for (int j = 0; j < N; j++) {
                        temp[i][j] = 0;
                    }
                }
            }
            for (int i = 0; i < N - 1; i++) free(numbers[i]);
            free(numbers);
            numbers = temp;
        }
        if (operation == 1) {
            numbers[operations[0] - 1][operations[1] - 1] = operations[2];
            numbers[operations[1] - 1][operations[0] - 1] = operations[2];
        }
        if (operation == 2) {
            int **temp;
            N--;
            temp = (int **)malloc(sizeof(int *) * N);
            for (int i = 0; i < N; i++) temp[i] = (int *)malloc(sizeof(int) * N);
            int v = operations[0];

            for (int i = 0; i < v - 1; i++) {
                for (int j = 0; j < v - 1; j++) {
                    temp[i][j] = numbers[i][j];
                }
                for (int j = v; j < N + 1; j++) {
                    temp[i][j - 1] = numbers[i][j];
                }
            }
            for (int i = v; i < N + 1; i++) {
                for (int j = 0; j < v; j++) {
                    temp[i - 1][j] = numbers[i][j];
                }
                for (int j = v; j < N + 1; j++) {
                    temp[i - 1][j - 1] = numbers[i][j];
                }
            }
            for (int i = 0; i < N - 1; i++) free(numbers[i]);
            free(numbers);
            numbers = temp;
        }
        if (operation == 3) {
            numbers[operations[0] - 1][operations[1] - 1] = 0;
            numbers[operations[1] - 1][operations[0] - 1] = 0;
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cout << numbers[i][j];
            if (j != N - 1) cout << " ";
        }
        cout << endl;
    }

    return 0;
}